#include <cstdio>
constexpr int Mod1 = 975'432'499;
constexpr int Mod2 = 997'543'249;
int a, b, c;
inline long long fsp(long long x, long long y, long long Mod = 998'244'353)
{
    long long res = 1;
    for (; y != 0;)
    {
        if (y & 1)
        {
            res *= x;
            res %= Mod;
        }
        x *= x;
        x %= Mod;
        y >>= 1;
    }
    return res;
}
inline bool check(long long x, long long y, long long z)
{
    return fsp(y, x, Mod1) == fsp(x, z, Mod1) && fsp(y, x, Mod2) == fsp(x, z, Mod2);
}
inline void solve()
{
    scanf("%d%d%d", &a, &b, &c);
    int answer = 0;
    for (int i = 1; i <= a; i++)
    {
        for (int j = 1; j <= b; j++)
        {
            for (int k = 1; k <= c; k++)
            {
                if (check(i, j, k))
                {
                    answer++;
                }
            }
        }
    }
    printf("%d\n", answer);
}
int main()
{
    freopen("alien.in", "r", stdin);
    freopen("alien.out", "w", stdout);
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}